import axios from 'axios';
import { Message } from 'element-ui'
var service = axios.create({
	baseURL: process.env.BASE_API,
	timeout: 5000
})
var cancel;
export default {
	//这里是请求地址
  // baseUrl_http: 'http://192.168.12.109:8881/hualiang',
	baseUrl_http: 'http://125.46.15.250:8881/hualiang',
	// baseUrl_http: '',
	get(url, data) {
		url = this.baseUrl_http + url;
		return new Promise((resolve, reject) => {
			service({
				method: 'get',
				url,
				params: data
			}).then(res => {
				if (res.status == 200) {
					resolve({
						code: 1,
						data: res.data
					})
				} else {
					resolve({
						code: 0
					})
				}
			}).catch(err => {
				console.log(err, '异常')
			})

		})
	},
	post(url, data) {
		url = this.baseUrl_http + url;
		return new Promise((resolve, reject) => {
			service({
				method: 'post',
				url,
				data: data
			}).then(res => {
				if (res.status == 200) {
					resolve({
						code: 1,
						data: res.data
					})
				} else {
					resolve({
						code: 0
					})
				}
			}).catch(err => {
				console.log(err, '异常')
			})
		})
	},
	postBlob(url, data) {
		url = this.baseUrl_http + url;
		return new Promise((resolve, reject) => {
			service({
				method: 'post',
				url,
				data: data,
        responseType: 'blob'
			}).then(res => {
        resolve(res.data)
			}).catch(err => {
				console.log(err, '异常')
			})
		})
	},

	show_msg() {
		Message('暂未开发，敬请期待');
	}
}
service.interceptors.request.use(config => {
  const token = localStorage.getItem('token')
  if (token) {
    config.headers[ 'X-Access-Token' ] = token // 让每个请求携带自定义 token 请根据实际情况自行修改
  }
  return config
}, (error) => {
  return Promise.reject(error)
})
